package com.sia.springcloud.protocol.model;

import com.sia.springcloud.model.Device;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * @Author: Sirius
 * @Date: 2022/1/2 15:19
 * @Description:
 **/
@Slf4j
@Data
public class OpcuaDevice implements Serializable {
    private Integer id;
    private Integer collect;
    private String microservice;
    private String protocolName;
    private String deviceName;
    private String description;
    private String host;
    private Integer port;
    private String securityMode;
    private String username;
    private String password;
    private String servername;
    private static final long serialVersionUID = 1L;

    /**
     * 将Modbus设备对象转换成Protocol设备对象
     *
     * @param opcuaDevice
     * @return
     */
    public static Device convert(OpcuaDevice opcuaDevice) {
        Device device = new Device();
        device.setId(opcuaDevice.getId());
        device.setCollect(opcuaDevice.getCollect());
        device.setMicroservice(opcuaDevice.getMicroservice());
        device.setProtocolName(opcuaDevice.getProtocolName());
        device.setDeviceName(opcuaDevice.getDeviceName());
        device.setDescription(opcuaDevice.getDescription());
        device.setHost(opcuaDevice.getHost());
        device.setPort(opcuaDevice.getPort());
        device.setVarStr1(opcuaDevice.getSecurityMode());
        device.setUsername(opcuaDevice.getUsername());
        device.setPassword(opcuaDevice.getPassword());
        device.setServerId(opcuaDevice.getServername());
        return device;
    }

    /**
     * 将Protocol设备对象转换成Modbus设备对象
     *
     * @param device
     * @return
     */
    public static OpcuaDevice reconvert(Device device) {

        OpcuaDevice opcuaDevice = new OpcuaDevice();

        opcuaDevice.setId(device.getId());
        opcuaDevice.setCollect(device.getCollect());
        opcuaDevice.setMicroservice(device.getMicroservice());
        opcuaDevice.setProtocolName(device.getProtocolName());
        opcuaDevice.setDeviceName(device.getDeviceName());
        opcuaDevice.setDescription(device.getDescription());
        opcuaDevice.setHost(device.getHost());
        opcuaDevice.setPort(device.getPort());
        opcuaDevice.setSecurityMode(device.getVarStr1());
        opcuaDevice.setUsername(device.getUsername());
        opcuaDevice.setPassword(device.getPassword());
        opcuaDevice.setServername(device.getServerId());

        return opcuaDevice;
    }
}
